//
//  UIImage+Extension.swift
//  picturePickerView
//
//  Created by sunjinliang on 15/12/18.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

import UIKit
extension UIImage{
    func scaleToWidth(Width: CGFloat) -> UIImage{
        
        if Width > size.width{
            return self
        }
        let height = size.height * Width / size.width
        let rect = CGRect(x: 0, y: 0, width: Width, height: height)
        
        UIGraphicsBeginImageContext(rect.size)
        self.drawInRect(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
        
    }
    
    
    
}
